<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.2">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/avatar.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/avatar.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/avatar.png">
  <link rel="mask-icon" href="/images/avatar.png" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"notes.maxwi.com","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":true,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":true,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="关于动态链接库和静态链接库的区别可以参考另一篇笔记，其实也就一句话：静态链接库在编译期加载到相应的编译目标中（编译后不再需要），而动态链接库是在运行期由执行目标进行调用（每次运行都需要）。Windows下动态链接库以后缀.dll标识，Linux下的动态链接库命名为libxxx.so，其中xxx为库名称。">
<meta property="og:type" content="article">
<meta property="og:title" content="Windows和Linux下的动态链接库的编译、链接和引用相关问题">
<meta property="og:url" content="http://notes.maxwi.com/2017/12/01/dll-lib-export-for-windows/index.html">
<meta property="og:site_name" content="blueyi&#39;s notes">
<meta property="og:description" content="关于动态链接库和静态链接库的区别可以参考另一篇笔记，其实也就一句话：静态链接库在编译期加载到相应的编译目标中（编译后不再需要），而动态链接库是在运行期由执行目标进行调用（每次运行都需要）。Windows下动态链接库以后缀.dll标识，Linux下的动态链接库命名为libxxx.so，其中xxx为库名称。">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2017-12-01T08:31:54.000Z">
<meta property="article:modified_time" content="2017-12-01T08:31:54.000Z">
<meta property="article:author" content="blueyi">
<meta property="article:tag" content="Dev">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://notes.maxwi.com/2017/12/01/dll-lib-export-for-windows/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'en'
  };
</script>

  <title>Windows和Linux下的动态链接库的编译、链接和引用相关问题 | blueyi's notes</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="blueyi's notes" type="application/atom+xml">
<link rel="alternate" href="/rss2.xml" title="blueyi's notes" type="application/rss+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">blueyi's notes</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Follow Excellence,Success will chase you!</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>Categories</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>Tags</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>About</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>Search
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="Searching..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="http://notes.maxwi.com/2017/12/01/dll-lib-export-for-windows/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/default_avatar.jpg">
      <meta itemprop="name" content="blueyi">
      <meta itemprop="description" content="心怀善意，虛怀若谷！">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="blueyi's notes">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Windows和Linux下的动态链接库的编译、链接和引用相关问题
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2017-12-01 16:31:54" itemprop="dateCreated datePublished" datetime="2017-12-01T16:31:54+08:00">2017-12-01</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Dev/" itemprop="url" rel="index"><span itemprop="name">Dev</span></a>
                </span>
            </span>

          <br>
            <span class="post-meta-item" title="Symbols count in article">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">Symbols count in article: </span>
              <span>2.7k</span>
            </span>
            <span class="post-meta-item" title="Reading time">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">Reading time &asymp;</span>
              <span>2 mins.</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>关于动态链接库和静态链接库的区别可以参考另一篇笔记，其实也就一句话：静态链接库在编译期加载到相应的编译目标中（编译后不再需要），而动态链接库是在运行期由执行目标进行调用（每次运行都需要）。<br>Windows下动态链接库以后缀<code>.dll</code>标识，Linux下的动态链接库命名为<code>libxxx.so</code>，其中<code>xxx</code>为库名称。</p>
<span id="more"></span>

<h2 id="Windows下配置VS编译生成dll动态库和相应的lib文件"><a href="#Windows下配置VS编译生成dll动态库和相应的lib文件" class="headerlink" title="Windows下配置VS编译生成dll动态库和相应的lib文件"></a>Windows下配置VS编译生成dll动态库和相应的lib文件</h2><p>当我们的项目生成为DLL库提供给调用方使用时，同时还需要提供lib文件和头文件，如果只有头文件，VS编译时将会报错，因为编译器需要从相应的lib中查找需要引用的相关函数。该lib文件与静态库的lib文件不同的是它要小的多，其中并不包含实际相关函数实现，只是包含了需要引用的函数声明信息。该lib同样也只是在调用方编译时用一次，运行时只需要提供相应的DLL即可。所以我们除了创建能够生成DLL的项目之外，还需要配置VS生成包含指定函数的lib文件。</p>
<h3 id="创建生成DLL的项目"><a href="#创建生成DLL的项目" class="headerlink" title="创建生成DLL的项目"></a>创建生成DLL的项目</h3><p>创建VS的WIN32应用程序项目时，将“应用程序类型”直接选择为<code>DLL</code>即可。也可以创建一个普通的控制台项目，然后在项目属性——常规——配置类型中设置为动态库(.dll)。</p>
<h3 id="配置输出lib和dll"><a href="#配置输出lib和dll" class="headerlink" title="配置输出lib和dll"></a>配置输出lib和dll</h3><p>创建完DLL项目，或者在项目属性中更改项目类型为DLL之后，编译生成的目标文件即为相应的DLL，我们只需要配置能够生成lib即可。可以指定某些函数生成到lib中，相当于我们只暴露指定的函数给调用方。有2种方式来指定生成lib文件：</p>
<h4 id="通过-declspec-dllexport-生成lib"><a href="#通过-declspec-dllexport-生成lib" class="headerlink" title="通过_declspec(dllexport)生成lib"></a>通过<code>_declspec(dllexport)</code>生成lib</h4><p>只需要在要导出的函数声明前使用<code>_declspec(dllexport)</code>即可导出为lib，该方式不是很灵活，当需要添加函数时，添加的函数都需要在源码中添加该声明。<br>下面举例说明：<br><strong>创建一个DLL工程</strong><br>新建头文件<code>testDll.h</code>，内容如下：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">ifndef</span> TEST_DLL_H</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> TEST_DLL_H</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;string&gt;</span></span></span><br><span class="line"></span><br><span class="line">_declspec(dllexport) <span class="function"><span class="type">void</span> <span class="title">print</span><span class="params">(<span class="type">const</span> std::string &amp;str)</span></span>;</span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br></pre></td></tr></table></figure>

<p>新建<code>testDll.cpp</code>，内容如下：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&quot;testDll.h&quot;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">print</span><span class="params">(<span class="type">const</span> std::string &amp;str)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    std::cout &lt;&lt; <span class="string">&quot;Come from dynamic library!\n&quot;</span> &lt;&lt; str &lt;&lt; std::endl;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>然后编译之后可以看到生成了<code>TestDll.lib</code>和<code>TestDll.dll</code>两个文件，如果上面在声明时不使用<code>_declspec(dllexport)</code>，只会生成dll，不会生成<code>lib</code>。</p>
<p><strong>引用DLL</strong></p>
<p>同一个解决方案下新建一个项目<code>TestDemo</code>，新建一个解决方案也是一样的，在同一个解决方案中省了指定lib路径和拷贝dll。<br>新建<code>testDemo.cpp</code>，内容为：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&quot;testDll.h&quot;</span></span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">(<span class="type">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&quot;Hello World!&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>编辑项目属性，其中“通用属性——引用”中添加刚才那个DLL的项目，最好再启用“复制本地”，这样DLL生成之后就会自动引用到这里。在“配置属性——C/C++——常规”中附加包含目录添加含有<code>testDll.h</code>的路径。</p>
<p>现在编译之后就可以直接运行了。</p>
<p>附送一份跨平台的通用宏定义：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">ifdef</span> WIN32</span></span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> _WINDLL</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> DLL_API _declspec(dllexport)  <span class="comment">// 用于DLL生成的导入导出</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">else</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> DLL_API _declspec(dllimport)</span></span><br><span class="line"><span class="meta">#<span class="keyword">endif</span>  <span class="comment">// _WINDLL</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">else</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> DLL_API</span></span><br><span class="line"><span class="meta">#<span class="keyword">ifndef</span> __stdcall  <span class="comment">// 用于指定函数参数调用中的压栈和清理顺序</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> __stdcall</span></span><br><span class="line"><span class="meta">#<span class="keyword">endif</span>  <span class="comment">// __stdcall</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">endif</span>  <span class="comment">// WIN32</span></span></span><br></pre></td></tr></table></figure>

<p>该部分内容放在用于生成DLL项目的相关头文件中，后面需要导出到DLL中的函数都用宏<code>DLL_API</code>修饰，这样当这个项目编译时将会自动生成相应的DLL文件和lib文件，lib文件中将会含有被<code>_declspec(dllexport)</code>修饰的函数，以便用于其他项目的链接。</p>
<h4 id="通过-def文件生成lib"><a href="#通过-def文件生成lib" class="headerlink" title="通过.def文件生成lib"></a>通过<code>.def</code>文件生成lib</h4><p>也可以在项目中添加一个后缀为<code>.def</code>的文件，文件内容如下来指定DLL导出的文件相关信息，例如针对上面的代码，删除其中的<code>_declspec(dllexport)</code>，添加文件<code>Dllexport.def</code>（新建项，然后搜索def即可），内容：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">; export for dll</span><br><span class="line">LIBRARY TestDll</span><br><span class="line"></span><br><span class="line">EXPORTS</span><br><span class="line">    print</span><br></pre></td></tr></table></figure>

<p>其中<code>;</code>后面为注释，<code>LIBRARY</code>后面跟导出库的名字，<code>EXPORTS</code>后面为需要导出库中包含的函数。<br>这种方式更加灵活</p>
<h2 id="Linux下动态链接库的生成和调用"><a href="#Linux下动态链接库的生成和调用" class="headerlink" title="Linux下动态链接库的生成和调用"></a>Linux下动态链接库的生成和调用</h2><p>linux下容易的多，只需要生成一个<code>libxxx.so</code>文件，然后引用的时候在编译期通过<code>-lxxx</code>加入对该so的引用即可。<br>还以上面例子中的三个代码文件为例，</p>
<h3 id="编译动态链接库"><a href="#编译动态链接库" class="headerlink" title="编译动态链接库"></a>编译动态链接库</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">g++ -fPIC -shared -o libtestDll.so</span><br></pre></td></tr></table></figure>

<p>其中<code>-shared</code>指定生成动态链接库，否则默认输出可执行文件，<code>-fPIC</code>表示编译为位置独立的代码，不用此选项的话编译后的代码是位置相关的所以动态载入时是通过代码拷贝的方式来满足不同进程的需要，而不能达到真正代码段共享的目的。</p>
<h3 id="引用动态链接库"><a href="#引用动态链接库" class="headerlink" title="引用动态链接库"></a>引用动态链接库</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">g++ -o testDemo testDemo.cpp -ltestDll -L.</span><br></pre></td></tr></table></figure>

<p>其中<code>-l</code>表示引用的动态链接库名，<code>-L.</code>用于指定动态链接库查找路径包含当前目录。<br>编译完成之后运行会报错，动态链接库不存在，需要指定动态链接库运行时查找路径：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">export</span> LD_LIBRARY_PATH=.</span><br></pre></td></tr></table></figure>

<p>或者将需要的路径加入到<code>/etc/ld.so.conf</code>后，运行<code>sudo ldconfig</code>来更新缓存。</p>
<p>关于Linux下动态链接库编译、链接和运行时加载的问题可以参考这里：<a href="http://notes.maxwi.com/2017/04/13/linux-dynamic-lib-ldconfig/">http://notes.maxwi.com/2017/04/13/linux-dynamic-lib-ldconfig/</a></p>

    </div>

    
    
    
        

  <div class="followme">
    <p>Welcome to my other publishing channels</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Dev/" rel="tag"># Dev</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2017/11/29/gtest/" rel="prev" title="Google Test(gtest)使用">
      <i class="fa fa-chevron-left"></i> Google Test(gtest)使用
    </a></div>
      <div class="post-nav-item">
    <a href="/2017/12/03/coredump/" rel="next" title="gdb调试coredump文件">
      gdb调试coredump文件 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="gitalk-container"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Windows%E4%B8%8B%E9%85%8D%E7%BD%AEVS%E7%BC%96%E8%AF%91%E7%94%9F%E6%88%90dll%E5%8A%A8%E6%80%81%E5%BA%93%E5%92%8C%E7%9B%B8%E5%BA%94%E7%9A%84lib%E6%96%87%E4%BB%B6"><span class="nav-number">1.</span> <span class="nav-text">Windows下配置VS编译生成dll动态库和相应的lib文件</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E7%94%9F%E6%88%90DLL%E7%9A%84%E9%A1%B9%E7%9B%AE"><span class="nav-number">1.1.</span> <span class="nav-text">创建生成DLL的项目</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%85%8D%E7%BD%AE%E8%BE%93%E5%87%BAlib%E5%92%8Cdll"><span class="nav-number">1.2.</span> <span class="nav-text">配置输出lib和dll</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%80%9A%E8%BF%87-declspec-dllexport-%E7%94%9F%E6%88%90lib"><span class="nav-number">1.2.1.</span> <span class="nav-text">通过_declspec(dllexport)生成lib</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%80%9A%E8%BF%87-def%E6%96%87%E4%BB%B6%E7%94%9F%E6%88%90lib"><span class="nav-number">1.2.2.</span> <span class="nav-text">通过.def文件生成lib</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Linux%E4%B8%8B%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E5%BA%93%E7%9A%84%E7%94%9F%E6%88%90%E5%92%8C%E8%B0%83%E7%94%A8"><span class="nav-number">2.</span> <span class="nav-text">Linux下动态链接库的生成和调用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%BC%96%E8%AF%91%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E5%BA%93"><span class="nav-number">2.1.</span> <span class="nav-text">编译动态链接库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%BC%95%E7%94%A8%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E5%BA%93"><span class="nav-number">2.2.</span> <span class="nav-text">引用动态链接库</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="blueyi"
      src="/images/default_avatar.jpg">
  <p class="site-author-name" itemprop="name">blueyi</p>
  <div class="site-description" itemprop="description">心怀善意，虛怀若谷！</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">104</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">26</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">68</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/blueyi" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;blueyi" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://maxwi.com/" title="http:&#x2F;&#x2F;maxwi.com" rel="noopener" target="_blank">Maxwi</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2014 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">blueyi</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="Symbols count total">750k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="Reading time total">11:22</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a>
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/pjax/pjax.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>

<script src="/js/utils.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>

<script src="/js/bookmark.js"></script>

  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '.languages',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[data-pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.dataset.pjax !== undefined) {
      script.dataset.pjax = '';
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>




  
  <script data-pjax>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>




  
<script src="/js/local-search.js"></script>













    <div id="pjax">
  

  

<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.css">

<script>
NexT.utils.loadComments(document.querySelector('#gitalk-container'), () => {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js', () => {
    var gitalk = new Gitalk({
      clientID    : '0f8243eb2c8b2207980f',
      clientSecret: 'd159633a33519d3b7a48b0ca729032f7d1f38a41',
      repo        : 'notes',
      owner       : 'blueyi',
      admin       : ['blueyi'],
      id          : '7efa6b10593bd5f555fcf78ec5310b17',
        language: '',
      distractionFreeMode: true
    });
    gitalk.render('gitalk-container');
  }, window.Gitalk);
});
</script>

    </div>
</body>
</html>
